package com.fh.common.distributedlock;

import org.springframework.data.redis.core.RedisTemplate;

import com.fh.common.distributedlock.redis.BaseRedisDistributeLock;
import com.fh.common.distributedlock.redis.ClusterRedisDistributeLock;

/**
 * @author Qiu,Junda 
 * @date 2019年5月26日
 * @description
 */
public class DefaultDistributeLockBuilder implements DistributeLockBuilder{

	@Override
	public DistributeLock build(DLockType lockType,RedisTemplate<String, Object> redisTemplate) {
		switch (lockType) {
		case BASE_REDIS_LOCK:{
			return buildBaseRedisLock(redisTemplate);
		}
		case CLUSTER_REDIS_LOCK:{
			return buildClusterRedisLock(redisTemplate);
		}
		default:
			break;
		}
		throw new DistributeLockException("not create distribute lock error");
	}
	
	private DistributeLock buildBaseRedisLock(RedisTemplate<String, Object> redisTemplate) {
		return new BaseRedisDistributeLock(redisTemplate);
	}
	
	private DistributeLock buildClusterRedisLock(RedisTemplate<String, Object> redisTemplate) {
		return new ClusterRedisDistributeLock(redisTemplate);
	}

}
